package pri.zxx.webdemo.utils;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

/**
 * @author Twilight
 * @desc
 * @createTime 2020-06-05-21:37
 */
public class GsonUtil {
    public static final Gson gson;

    static {
        GsonBuilder gsonBuilder = new GsonBuilder();
        gson = gsonBuilder.serializeNulls().enableComplexMapKeySerialization()
                .serializeSpecialFloatingPointValues().create();
    }

    public static String toJson(Object o) {
        return gson.toJson(o);
    }

    public static <T> T fromJson(String json, Class<T> aClass) {
        return gson.fromJson(json, aClass);
    }
}
